package exercises

import (
	"fmt"
	"math"
	"math/rand"
	"time"
)

//输入某年某月，得到对应的天数
func Test1(year, month int) {
	if year%400 == 0 || (year%4 == 0 && year%100 != 0) {
		if month == 2 {
			fmt.Println(29)
		} else if month == 4 || month == 6 || month == 9 || month == 11 {
			fmt.Println(30)
		} else {
			fmt.Println(31)
		}
	} else {
		if month == 2 {
			fmt.Println(28)
		} else if month == 4 || month == 6 || month == 9 || month == 11 {
			fmt.Println(30)
		} else {
			fmt.Println(31)
		}
	}
}

//猜数字游戏
func Test2() {
	rand.Seed(time.Now().Unix())
	a := rand.Intn(10)
	fmt.Println(a)
	b := 0
	i := 0
	for ; i < 3; i++ {
		fmt.Println("请输入数字:")
		fmt.Scanln(&b)
		if a == b {
			break
		}
	}
	if i == 0 {
		fmt.Println("厉害了，一次就对了")
	} else if i < 3 {
		fmt.Println("恭喜最终猜对了")
	} else {
		fmt.Println("真遗憾最终也没猜对")
	}

}

//输出100以内素数，并求和
func Test3() {
	sum := 0
	for i := 2; i < 101; i++ {
		isprime := 1
		for j := 2; j <= int(math.Sqrt(float64(i))); j++ {
			if i%j == 0 {
				isprime = 0
				break
			}
		}
		if isprime == 1 {
			fmt.Printf("%d ", i)
			sum += i
		}
	}
	fmt.Printf("\n前100素数和为%d", sum)
}

//判断打鱼还是晒网
func Test4() {
	t1, _ := time.Parse("2006-01-02", "1990-01-01")
	temp := ""
	fmt.Println("请输入日期:")
	fmt.Scanln(&temp)
	t2, _ := time.Parse("2006-01-02", temp)
	subdate := ((t2.Unix() - t1.Unix()) / 86400) + 1
	switch subdate % 5 {
	case 1, 2, 3:
		fmt.Println("打鱼")
	default:
		fmt.Println("筛网")
	}

}

//小小计算器
func Test5() {
	fmt.Println("---------------------小小计算器--------------------")
	fmt.Println("1.加法\n2.减法\n3.乘法\n4.除法\n0.退出")
	fmt.Println("请输入需要运算的数字:")
	var a, b, c int
	fmt.Scanln(&a, &b)
	fmt.Println(a, b)
	fmt.Println("请输入运算选项:")
	fmt.Scanln(&c)
	switch c {
	case 0:
		fmt.Printf("")
	case 1:
		fmt.Println(a + b)
	case 2:
		fmt.Println(a - b)
	case 3:
		fmt.Println(a * b)
	case 4:
		fmt.Printf("%.2f", float64(a)/float64(b))

	}
}

//输出小写的a-z和大写的A-Z
func Test6() {
	var a byte
	for a = 'a'; a <= 'z'; a++ {
		fmt.Printf("%c-", a)
	}
	fmt.Println()
	var b byte
	for b = 'A'; b <= 'Z'; b++ {
		fmt.Printf("%c-", b)
	}
}
